<template>
    <section>
        <!--工具条-->
        <div class="searchgrid">
            <div style="float:left;">
                <el-select size="small" style="width:150px" v-model="post_data.where.status" placeholder="用户状态筛选" clearable @change="changeSelect">
                    <el-option
                            v-for="item in status_list"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div style="float: right;">
                <input v-model="post_data.search.id" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:账户号码">
                <input v-model="post_data.has.client.search.cellphone" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:手机号">
              <input class="yl-input-button" value=" 查询 " type="button" v-on:click="search">
            </div>

        </div>

        <!--列表-->
        <el-table :data="forms.list"
                  highlight-current-row
                  v-loading="loading"
                  style="width: 100%;">
            <el-table-column label="账户号码" prop="id" show-overflow-tooltip></el-table-column>
            <el-table-column label="客户id" prop="cust_id" show-overflow-tooltip></el-table-column>
            <el-table-column label="客户姓名" prop="client.nick_name" show-overflow-tooltip></el-table-column>
            <el-table-column label="手机号码" prop="client.cellphone" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品名称" prop="stock_finance_product.product_name" show-overflow-tooltip></el-table-column>
            <el-table-column label="借款金额" prop="current_finance_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="保证金" prop="total_caution" show-overflow-tooltip></el-table-column>
            <el-table-column label="操盘倍数" prop="stock_finance_product.product_times" show-overflow-tooltip></el-table-column>
            <el-table-column label="预警线金额" prop="precautious_line_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="平仓线金额" prop="liiquidation_line_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="申请日期" prop="stock_finance_begin_time" min-width="130" show-overflow-tooltip></el-table-column>
            <el-table-column label="用户状态" prop="status" show-overflow-tooltip></el-table-column>

            <el-table-column label="操作">
                <template scope="scope">
                    <a href="javascript:void(0);" @click="openInterest(scope.row)">付息详情</a>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <div class="pagination">
            <el-col :span="24" class="toolbar">
                <el-pagination
                        @size-change="changeSize"
                        @current-change="pageChange"
                        :current-page="post_data.offset/post_data.limit+1"
                        :page-sizes="[15, 30, 45, 60]"
                        :page-size="post_data.limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="forms.count"
                        style="float:left;">
                </el-pagination>
            </el-col>
        </div>

        <el-dialog
                title="付息详情"
                :visible.sync="dialog1Visible"
                top="150px">
            <el-table :data="form1">
                <el-table-column property="id" label="ID"></el-table-column>
                <el-table-column property="total_insterests" label="递延费金额"></el-table-column>
                <el-table-column property="account_left" label="账户余额"></el-table-column>
                <el-table-column property="created_time" min-width="130" label="收费时间"></el-table-column>
                <el-table-column v-if="isUserSystemAdmin" prop="remark" label="备注"></el-table-column>
                <el-table-column property="is_paid_over" label="状态"></el-table-column>
            </el-table>
        </el-dialog>
    </section>
</template>


<script type="text/ecmascript-6">
    import {getUStockFinancings, getUStockFinanceInterestPercentagesSFID} from '../../../api/stock';
    export default {
        data() {
            return {
                status_list: [{value: 1, label: '操盘中'}, {value: 2, label: '单向冻结'}, {value: 3, label: '双向冻结'}, {value: 4, label: '已结算'}],
                loading: false,
                forms: {},
                form1: [],
                dialog1Visible: false,
                post_data: {
                    field: ['id', 'cust_id', 'product_id', 'status', 'stock_finance_begin_time', 'available_amount',
                        'precautious_line_amount', 'liiquidation_line_amount', 'init_caution_money', 'post_finance_caution_money',
                        'post_add_caution_money', 'current_finance_amount', '"" as total_caution'],
                    search: {
                        id: ''
                    },
                    where: {
                        status: ''
                    },
                    count: true,
                    offset: 0,
                    limit: 15,
                    stock_finance_product: {
                        field: ['id', 'product_name', 'product_times']
                    },
                    client: {
                        field: ['id', 'nick_name', 'cellphone']
                    },
                    has: {
                        client: {
                            search: {
                                cellphone: ''
                            }
                        }
                    },
                    order: 'id desc'
                }
            }
        },
        created(){
            this.getList();
        },
        methods: {
            getList: function () {
                this.loading = true;
                getUStockFinancings(this.post_data).then(res => {
                    this.loading = false;
                    if (res.status === 0) return this.ezNotifyAxiosThen(res);
                    this.forms = res.data;
                }).catch(error => this.ezNotifyAxiosCatch(error));
            },
            pageChange: function (index) {
                this.post_data.offset = (index - 1) * this.post_data.limit;
                this.getList();
            },
            changeSize: function (num) {
                this.post_data.offset = 0;
                this.post_data.limit = num;
                this.getList();
            },
            search: function () {
                this.post_data.offset = 0;
                this.getList();
            },
            changeSelect: function (value) {
                this.post_data.offset = 0;
                this.getList();
            },
            openInterest: function (row) {
                this.dialog1Visible = true;
                this.loading = true;
                let interestPercentagePostData = {
                    field: ['id', 'cust_id', 'stock_finance_id', 'total_insterests', 'account_left', 'is_paid_over', 'remark', 'created_time',
                        'cust_id'],
                };
                getUStockFinanceInterestPercentagesSFID(row.id, interestPercentagePostData).then(res => {
                    this.form1 = res.data.list;
                    this.loading = false;
                }).catch(error => this.ezNotifyAxiosCatch(error));
            }
        }
    }
</script>

<style scoped>
</style>
